<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>注册</title>
</head>
<script src="js/jquery-3.7.1.js"></script>
<body>
<h1 align="center">登录</h1>
<table align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="right">用户名：</td>
    <td><input type="text" id="userName"></td>
  </tr>
  <tr>
    <td align="right">密码：</td>
    <td><input type="password" id="pwd1"></td>
  </tr>
  <tr>
    <td align="right">确认密码：</td>
    <td><input type="password" id="pwd2"></td>
  </tr>
  <tr>
    <td align="right">联系电话：</td>
    <td><input type="text" id="phone"></td>
  </tr>
  <tr>
    <td align="right">邮箱地址：</td>
    <td><input type="text" id="email"></td>
  </tr>
</table>
<div style="margin: auto;text-align: center">
  <button id="reg">注册</button>
  <div id="error"></div>
</div>
</body>
<script>
  function reg(){
    $.ajax({
      url:"reg.do",
      type:"post",
      data:{
        userName:$("#userName").val(),
        pwd1:$("#pwd1").val(),
        pwd2:$("#pwd2").val(),
        phone:$("#phone").val(),
        email:$("#email").val()
      },
      success:function(data){
        if(data == "Yes"){
          if (confirm("注册成功！返回登录？")){
            location.href = "login.html";
          }
        }else{
          $("#error").text(data);
        }
      }
    })
  }
$("#reg").click(function(){
  reg();
});
</script>
</html>